package com.hb.core.pojo.sync;

import cn.hutool.db.ds.simple.SimpleDataSource;
import cn.hutool.db.meta.Column;
import cn.hutool.db.meta.MetaUtil;
import cn.hutool.db.meta.Table;
import lombok.Getter;
import lombok.Setter;

import javax.sql.DataSource;
import java.util.Collection;

/**
 * 数据库构建器
 *
 * @author zhaojk
 * @since 2022/4/16 0:04
 */
@Setter
@Getter
public class DataSourceBuilder {
    /**
     * 数据库用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * url
     */
    private String url;
    /**
     * driver
     */
    private String driverClassName;

    public DataSourceBuilder username(String username) {
        this.username = username;
        return this;
    }

    public DataSourceBuilder password(String password) {
        this.password = password;
        return this;
    }

    public DataSourceBuilder url(String url) {
        this.url = url;
        return this;
    }

    public DataSourceBuilder driverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
        return this;
    }

    public DataSource build() {
        return new SimpleDataSource(url, username, password, driverClassName);
    }

    /**
     * 获取数据源对象
     *
     * @return
     */
    public static DataSource buildDefault() {
        DataSourceBuilder builder = new DataSourceBuilder();
        builder.username("root")
                .password("12399123")
                .url("jdbc:mysql://local.fzznkj.com:13306/trade2_1_02_dev?useUnicode=true&characterEncoding=utf8&useSSL=true&allowMultiQueries=true&serverTimezone=Asia/Shanghai")
                .driverClassName("com.mysql.cj.jdbc.Driver");
        return builder.build();
    }

}
